//
//  RequestManager+interface.m
//  OrderFood
//
//  Created by leilei on 2018/11/12.
//  Copyright © 2018年 zhiyuan. All rights reserved.
//

#import "RequestManager+interface.h"

@implementation RequestManager (interface)


-(void)netWorkLogin:(NSString *)account andPwd:(NSString *)pwd success:(SuccessBlock)success failure:(FailureBlock)failure {
    
    NSString *url = @"/auth/rider/login";
    NSMutableDictionary *submit = [NSMutableDictionary dictionary];
    [submit setObject:account   forKey:@"name"];
    [submit setObject:pwd       forKey:@"password"];
    
    [self netPost:url data:submit success:^(NSDictionary * _Nonnull response) {
        if ( success ) {
            success( response );
        }
    } failure:^(NSString * _Nonnull message) {
        if ( failure ) {
            failure( message );
        }
    }];
}






/**
 获取两地点之间的距离和时间

 @param origin 用户坐标|店的坐标
 @param destination 店的坐标|用户的坐标
 @param success 成功返回
 @param failure 失败返回
 */
-(void)netWorkDistanceTime:(NSString *)origin andDestination:(NSString *)destination success:(SuccessBlock)success failure:(FailureBlock)failure {
    NSString *url = @"https://maps.googleapis.com/maps/api/distancematrix/json";
    NSMutableDictionary *submit = [NSMutableDictionary new];
    [submit setObject:origin forKey:@"origins"];
    [submit setObject:destination forKey:@"destinations"];
    [submit setObject:@"false" forKey:@"sensor"];
    [submit setObject:@"bicycling" forKey:@"mode"];
    [submit setObject:@"AIzaSyDU8SBtzx84CB2gf2kfZhC_Y9BRP6U7znw" forKey:@"key"];
    [self netGet:url data:submit success:^(NSDictionary * _Nonnull response) {
        if ( success ) {
            success( response );
        }
    } failure:^(NSString * _Nonnull message) {
        if ( failure ) {
            failure( message );
        }
    }];
}




/**
 获取待取餐列表

 @param success 成功返回
 @param failure 失败返回
 */
-(void)netWorkWait:(SuccessBlock)success failure:(FailureBlock)failure {
    
    NSString *url = @"/rider/work/order/list/obtain";
    NSMutableDictionary *submit = [NSMutableDictionary new];
    [self netPost:url data:submit success:^(NSDictionary * _Nonnull response) {
        if ( success ) {
            success( response );
        }
    } failure:^(NSString * _Nonnull message) {
        if ( failure ) {
            failure( message );
        }
    }];
}




/**
 接单

 @param orderId 订单id
 @param success 成功返回
 @param failure 失败返回
 */
-(void)netWorkGetOrder:(NSString *)orderId success:(SuccessBlock)success failure:(FailureBlock)failure {
    NSString *url = @"/rider/work/order/receive";
    NSMutableDictionary *submit = [NSMutableDictionary new];
    [submit setObject:orderId forKey:@"userOrderId"];
    [self netPost:url data:submit success:^(NSDictionary * _Nonnull response) {
        if ( success ) {
            success( response );
        }
    } failure:^(NSString * _Nonnull message) {
        if ( failure ) {
            failure( message );
        }
    }];
}



/**
 确认取餐

 @param orderId 订单id
 @param success 成功返回
 @param failure 失败返回
 */
-(void)netWorkGetFood:(NSString *)orderId success:(SuccessBlock)success failure:(FailureBlock)failure {
    NSString *url = @"/rider/work/order/obtain";
    NSMutableDictionary *submit = [NSMutableDictionary new];
    [submit setObject:orderId forKey:@"userOrderId"];
    [self netPost:url data:submit success:^(NSDictionary * _Nonnull response) {
        if ( success ) {
            success( response );
        }
    } failure:^(NSString * _Nonnull message) {
        if ( failure ) {
            failure( message );
        }
    }];
}





/**
 确认送达

 @param orderId 订单id
 @param success 成功返回
 @param failure 失败返回
 */
-(void)netWorkSendFinish:(NSString *)orderId success:(SuccessBlock)success failure:(FailureBlock)failure {
    NSString *url = @"/rider/work/order/finish";
    NSMutableDictionary *submit = [NSMutableDictionary new];
    [submit setObject:orderId forKey:@"userOrderId"];
    [self netPost:url data:submit success:^(NSDictionary * _Nonnull response) {
        if ( success ) {
            success( response );
        }
    } failure:^(NSString * _Nonnull message) {
        if ( failure ) {
            failure( message );
        }
    }];
}



/**
 获取已完成订单列表

 @param success 成功
 @param failure 失败
 */
-(void)netWorkFinishOrder:(SuccessBlock)success failure:(FailureBlock)failure {
    NSString *url = @"/rider/work/order/list/finish";
    NSMutableDictionary *submit = [NSMutableDictionary new];
    [self netPost:url data:submit success:^(NSDictionary * _Nonnull response) {
        if ( success ) {
            success( response );
        }
    } failure:^(NSString * _Nonnull message) {
        if ( failure ) {
            failure( message );
        }
    }];
}

/**
 获取上传凭证

 @param quantity 上传数量
 @param success 成功
 @param failure 失败
 */
-(void)netWorkAWSS3Zone:(NSInteger)quantity success:(SuccessBlock)success failure:(FailureBlock)failure {
    NSString *url = @"/auth/aws/sts/s3/put/multiple";
    NSMutableDictionary *submit = [NSMutableDictionary new];
    [submit setObject:@(quantity) forKey:@"quantity"];
    [self netPost:url data:submit success:^(NSDictionary * _Nonnull response) {
        if ( success ) {
            success( response );
        }
    } failure:^(NSString * _Nonnull message) {
        if ( failure ) {
            failure( message );
        }
    }];
}




/**
 提交异常

 @param orderId 订单ID
 @param content 异常原因
 @param imageArr 数组t图片地址
 @param success 成功
 @param failure 失败
 */
-(void)netWorkSubmitError:(NSString *)orderId andContent:(NSString *)content andImageArr:(NSArray *)imageArr success:(SuccessBlock)success failure:(FailureBlock)failure {
    NSString *url = @"/rider/work/order/feedback";
    NSMutableDictionary *submit = [NSMutableDictionary new];
    [submit setObject:orderId forKey:@"userOrderId"];
    [submit setObject:content forKey:@"content"];
    [submit setObject:imageArr forKey:@"thumbnailList"];
    [self netPost:url data:submit success:^(NSDictionary * _Nonnull response) {
        if ( success ) {
            success( response );
        }
    } failure:^(NSString * _Nonnull message) {
        if ( failure ) {
            failure( message );
        }
    }];
}


#pragma mark - 12-25接手
/**3.配送列表数据*/
- (void)requestDeliveryListSuccessBlock:(SuccessBlock)success failBlock:(FailureBlock)failure {
    [self netPost:kDeleveryListAPI data:@{} success:^(NSDictionary * _Nonnull response) {
        success(response);
    } failure:^(NSString * _Nonnull message) {
        failure(message);
    }];
}

/**5.开始配送*/
- (void)requestSendStartWithOrderId:(NSString *)userOrderId successBlock:(SuccessBlock)success failBlock:(FailureBlock)failure {
    NSDictionary *pardic = @{@"userOrderId":userOrderId};
    [self netPost:kSendBeginAPI data:pardic success:^(NSDictionary * _Nonnull response) {
        success(response);
    } failure:^(NSString * _Nonnull message) {
        failure(message);
    }];
}

/**6.确认送达*/
- (void)requestSendEndWithOrderId:(NSString *)userOrderId successBlock:(SuccessBlock)success failBlock:(FailureBlock)failure {
    
    NSDictionary *pardic = @{@"userOrderId":userOrderId};
    [self netPost:kSendEndAPI data:pardic success:^(NSDictionary * _Nonnull response) {
        
        success(response);
    } failure:^(NSString * _Nonnull message) {
        failure(message);
    }];
}


/**8.异常上报列表*/
- (void)requestExceptionReportListSuccessBlock:(SuccessBlock)success failBlock:(FailureBlock)failure {
    
    [self netPost:kExceptionReportListAPI data:@{} success:^(NSDictionary * _Nonnull response) {
        success(response);
    } failure:^(NSString * _Nonnull message) {
        failure(message);
    }];
}
/**11.佣金明细列表*/
- (void)requestCommissionListSuccessBlock:(SuccessBlock)success failBlock:(FailureBlock)failure {
    [self netPost:kCommissionListAPI data:@{} success:^(NSDictionary * _Nonnull response) {
        success(response);
    } failure:^(NSString * _Nonnull message) {
        
        failure(message);
    }];
}



/**13.我的页面*/
- (void)requestMySucessBlock:(SuccessBlock)success failBlock:(FailureBlock)failure {
    [self netPost:kMyAPI data:@{} success:^(NSDictionary * _Nonnull response) {
        success(response);
    } failure:^(NSString * _Nonnull message) {
        failure(message);
    }];
}


/**请求首页数据*/
- (void)requestHomeSuccessBlock:(SuccessBlock)success failureBlock:(FailureBlock)failure {
    //没有参数
    [self netPost:kHomeAPI data:@{} success:^(NSDictionary * _Nonnull response) {
        success(response);
    } failure:^(NSString * _Nonnull message) {
        failure(message);
    }];
    
}


/**15.修改密码*/
- (void)requestModifyPasswordWithOldPwd:(NSString *)oldpwd xinPwd:(NSString *)xinpwd successBlock:(SuccessBlock)success failBloc:(FailureBlock)failure {
    
    NSDictionary *pardic = @{@"oldPassword":oldpwd,
                             @"newPassword":xinpwd,
                             @"againNewPassword":xinpwd
                             };
    [self netPost:kModifyPassword data:pardic success:^(NSDictionary * _Nonnull response) {
        success(response);
    } failure:^(NSString * _Nonnull message) {
        failure(message);
    }];
}

@end
